package per.zqx.rabbit.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * RabbitTtlConfig,
 *
 * @author Sa, Zhang 2021-06-06 19:47
 */
@Configuration
public class RabbitTtlDlxConfig {

    @Bean
    public FanoutExchange fanoutTtl4DeadExchange() {
        return new FanoutExchange("fanout_ttl_Dead_order_exchange", true, false);
    }

    @Bean
    public Queue ttl4DeadFanoutQueue() {
        Map<String, Object> args = new HashMap<>();
        // 设置过期时间
        args.put("x-message-ttl", 5000);
        // 设置死信交换机
        args.put("x-dead-letter-exchange", "dead-fanout-exchange");
        // 一个未被消费者绑定的队列
        return new Queue("ttl.fanout.queue", true, false, false, args);
    }

    @Bean
    public Binding ttl4DeadFanoutSmsBinding() {
        return BindingBuilder.bind(ttl4DeadFanoutQueue()).to(fanoutTtl4DeadExchange());
    }
}
